package com.wookii.friedeggs.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

/**
 *@Author Nick.wu
 *Date 2023/9/25
 */

@Database(entities = [Student::class, Class::class, Teacher::class, Exam::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
    companion object {
        @Volatile
        private var INSTANCE: AppDatabase? = null
        fun getDatabase(context: Context): AppDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context,
                    AppDatabase::class.java,
                    "database-eggs")
                    .build()
                INSTANCE = instance
                instance
            }
        }
    }

    abstract fun studentDao(): StudentDao
    abstract fun examDao(): ExamDao

    abstract fun classDao(): ClassDao

}